import {
  baseUrl
} from '../config';
module.exports = {

  http(url, method, postData, doSuccess, doFail, doComplete) {

    var requrl = url;
    if (!url.includes("http")) {
      requrl = baseUrl + url;
    }
    wx.request({
      url: requrl,
      data: postData,
      method: method == 'post' ? 'post' : 'get', // 判断请求类型，除了值等于'post'外，其余值均视作get
      header: {
        'Accept': '*/*',
        'Content-Type': 'application/json'
      },
      success: function (res) {
        if (typeof doSuccess == "function") {
          console.log(res.data);
          doSuccess(res);
        }
      },
      fail: function (res) {
        if (typeof doFail == "function") {
          doFail(res);
          console.log(url + "返回失败：\n" + JSON.stringify(res));
        }
      },
      complete: function (res) {
        if (typeof doComplete == "function") {
          doComplete();
          console.log(url + "请求完成");
        }
      }
    });
  }
}